/* eslint-disable no-empty-pattern */
import { api_add, api_delById, api_modifyAll, api_queryById } from '@/api/crud'

import {
  api_delByIdReal,
  api_unDel,
  api_batchDel,
  api_batchDelReal,
  api_patchStatus,
  api_batchPatchStatus,
  api_batchMove,
  api_listPageEditor,
  api_recycleEditor,
  api_searchEditor,
  api_listPageChecker,
  api_searchChecker,
} from '@/api/article'

const pathName = 'article'

const state = {}

const mutations = {}

const actions = {
  // 添加
  add({}, article) {
    return new Promise((resolve, reject) => {
      api_add(pathName, article)
        .then(() => {
          resolve()
        })
        .catch((error) => {
          reject(error)
        })
    })
  },
  // 普通编辑逻辑删除一条文章
  delById({}, idArticle) {
    return new Promise((resolve, reject) => {
      api_delById(pathName, idArticle)
        .then(() => {
          resolve()
        })
        .catch((error) => {
          reject(error)
        })
    })
  },
  // 普通编辑真实删除一条文章
  delByIdReal({}, idArticle) {
    return new Promise((resolve, reject) => {
      api_delByIdReal(idArticle)
        .then(() => {
          resolve()
        })
        .catch((error) => {
          reject(error)
        })
    })
  },
  // 普通编辑批量逻辑删除文章
  batchDel({}, articleIds) {
    return new Promise((resolve, reject) => {
      api_batchDel(articleIds)
        .then(() => {
          resolve()
        })
        .catch((error) => {
          reject(error)
        })
    })
  },
  // 普通编辑真实批量删除文章
  batchDelReal({}, articleIds) {
    return new Promise((resolve, reject) => {
      api_batchDelReal(articleIds)
        .then(() => {
          resolve()
        })
        .catch((error) => {
          reject(error)
        })
    })
  },
  // 修改
  modifyAll({}, article) {
    return new Promise((resolve, reject) => {
      api_modifyAll(pathName, article)
        .then(() => {
          resolve()
        })
        .catch((error) => {
          reject(error)
        })
    })
  },
  // 设置文章状态
  patchStatus({}, paramsJson) {
    return new Promise((resolve, reject) => {
      api_patchStatus(paramsJson)
        .then(() => {
          resolve()
        })
        .catch((error) => {
          reject(error)
        })
    })
  },
  // 从回收站恢复文章
  unDel({}, idArticle) {
    return new Promise((resolve, reject) => {
      api_unDel(idArticle)
        .then(() => {
          resolve()
        })
        .catch((error) => {
          reject(error)
        })
    })
  },
  // 批量设置文章状态
  batchPatchStatus({}, paramsJson) {
    return new Promise((resolve, reject) => {
      api_batchPatchStatus(paramsJson)
        .then(() => {
          resolve()
        })
        .catch((error) => {
          reject(error)
        })
    })
  },
  // 批量移动文章
  batchMove({}, paramsJson) {
    return new Promise((resolve, reject) => {
      api_batchMove(paramsJson)
        .then(() => {
          resolve()
        })
        .catch((error) => {
          reject(error)
        })
    })
  },
  // 根据id查询到一个对象全部资料
  queryById({}, id) {
    return new Promise((resolve, reject) => {
      api_queryById(pathName, id)
        .then((response) => {
          resolve(response.data.data)
        })
        .catch((error) => {
          reject(error)
        })
    })
  },
  // ========== 普通编辑 ==========

  // 普通编辑得到自己添加的所有文章分页列表数据
  listPageEditor({}, paramsJson) {
    return new Promise((resolve, reject) => {
      api_listPageEditor(paramsJson)
        .then((response) => {
          resolve(response.data.data)
        })
        .catch((error) => {
          reject(error)
        })
    })
  },
  // 普通编辑得到自己回收站所有文章分页列表数据
  recycleEditor({}, paramsJson) {
    return new Promise((resolve, reject) => {
      api_recycleEditor(paramsJson)
        .then((response) => {
          resolve(response.data.data)
        })
        .catch((error) => {
          reject(error)
        })
    })
  },
  // 查询得到标题包含某关键字词的文章分页列表数据
  searchEditor({}, paramsJson) {
    return new Promise((resolve, reject) => {
      api_searchEditor(paramsJson)
        .then((response) => {
          resolve(response.data.data)
        })
        .catch((error) => {
          reject(error)
        })
    })
  },

  // ========== 审核、签发编辑、超管 ==========

  // 审核、签发编辑、超管得到所有待审文章分页列表数据
  listPageChecker({}, paramsJson) {
    return new Promise((resolve, reject) => {
      api_listPageChecker(paramsJson)
        .then((response) => {
          resolve(response.data.data)
        })
        .catch((error) => {
          reject(error)
        })
    })
  },
  // 审核、签发编辑、超管根据标题关键字词搜索所有文章分页列表数据
  searchChecker({}, paramsJson) {
    return new Promise((resolve, reject) => {
      api_searchChecker(paramsJson)
        .then((response) => {
          resolve(response.data.data)
        })
        .catch((error) => {
          reject(error)
        })
    })
  },
}

export default {
  namespaced: true,
  state,
  mutations,
  actions,
}
